package com.swt.gap.controller;


import com.swt.gap.common.PageResult;
import com.swt.gap.model.dto.SubscribeFileDTO;
import com.swt.gap.model.vo.TaskSubscribeDataVO;
import com.swt.gap.service.TaskSubscribeDataService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author sx
 * @date 2021/02/20
 */
@Api(tags = "304. 任务订阅的数据")
@RestController
@RequestMapping("/task/subscribe/data")
@Slf4j
public class TaskSubscribeDataController {

    private final TaskSubscribeDataService taskSubscribeDataService;

    public TaskSubscribeDataController(TaskSubscribeDataService taskSubscribeDataService) {
        this.taskSubscribeDataService = taskSubscribeDataService;
    }


    @GetMapping("/un-read")
    @ApiOperation(value = "获取未读取的订阅数据", notes = "获取未读取的订阅数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskIds", dataType = "array", paramType = "query"),
            @ApiImplicitParam(name = "status", dataType = "int", paramType = "query", value = "1未读，2已读；非必填，如不填默认1")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = TaskSubscribeDataVO.class, responseContainer = "List")})
    public ResponseEntity<List<TaskSubscribeDataVO>> getTaskSubscribe(@RequestParam Integer[] taskIds,
                                                                      @RequestParam(required = false) Integer status){
        return ResponseEntity.ok(taskSubscribeDataService.listTaskSubscribeDataUnread(taskIds, status));
    }

    @GetMapping("/task-data")
    @ApiOperation(value = "获取指定任务订阅的数据", notes = "获取指定任务订阅的数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskId", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "status", dataType = "int", paramType = "query", value = "1未读，2已读；非必填，如不填获取全部类型"),
            @ApiImplicitParam(name = "fileName", dataType = "string", paramType = "query", value = "文件名模糊匹配，不填则获取全部"),
            @ApiImplicitParam(name = "pageNum", dataType = "int", value = "获取的当前页码，默认从第一页开始"),
            @ApiImplicitParam(name = "pageSize", dataType = "int", value = "每页的条数")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = SubscribeFileDTO.class, responseContainer = "List")})
    public ResponseEntity<PageResult<SubscribeFileDTO>> getTaskSubscribe(@RequestParam Integer taskId,
                                                                         @RequestParam(required = false) Integer status,
                                                                         @RequestParam(required = false) String fileName,
                                                                         @RequestParam(value = "pageNum")Integer pageNum,
                                                                         @RequestParam(value = "pageSize")  Integer pageSize){
        return ResponseEntity.ok(taskSubscribeDataService.listTaskSubscribeData(taskId, status, fileName, pageNum, pageSize));
    }

    @PutMapping("/reed-status")
    @ApiOperation(value = "修改订阅数据状态为已读", notes = "修改订阅数据状态为已读")
    @ApiImplicitParam(name = "subscribeIds", dataType = "array", paramType = "query")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = Integer.class)})
    public ResponseEntity<Integer> updateStatusReed(@RequestParam Integer[] subscribeIds){
        return ResponseEntity.ok(taskSubscribeDataService.updateStatusReed(subscribeIds));
    }


    /*@DeleteMapping("{subscribeId}")
    @ApiOperation(value = "删除订阅数据", notes = "删除订阅数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "subscribeId", dataType = "int", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = Integer.class)})
    public ResponseEntity<Integer> deleteTaskSubscribeData(@PathVariable Integer subscribeId){
        return ResponseEntity.ok(taskSubscribeDataService.deleteTaskSubscribeData(subscribeId));
    }*/

    @DeleteMapping
    @ApiOperation(value = "删除订阅数据", notes = "删除订阅数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "subscribeIds", dataType = "array", paramType = "query")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = Integer.class)})
    public ResponseEntity<Integer> deleteTaskSubscribeData(@RequestParam Integer[] subscribeIds){
        return ResponseEntity.ok(taskSubscribeDataService.deleteTaskSubscribeData(subscribeIds));
    }
}
